$(function(){
	var copy = JSON.parse(getCookie('copy'));
	//console.log(copy);
	if(copy){
        $.each(copy.data, function(i,v) {
            $.each(v.depChaArr, function(ii,vv) {
                console.log(vv);
                $("#jieshou").val(vv.name);
                $("[name=recipient]").val(vv.len);
            });
        });
	}

	
	var dateTiem = getNowFormatDate();
	$('#dateTime').val(dateTiem);
	var num = 0;
	$('.xiangce').on('change',function(){
		var _this = this;
		loadImg(_this);
	})
	function loadImg(_this){
		var defaultImg = '<a class="defaultImg" href="#sheet1">'+
							'<img src="images/addImg.png">'+
						'</a>';
		num = $('.addImg').find('a').length;
		console.log('触发',_this);
		mui('#sheet1').popover('toggle');
		var file = _this.files[0];  
  		
	    //创建读取文件的对象  
	    var reader = new FileReader();  
	  
	    //创建文件读取相关的变量  
	    var imgFile;  
	  
	    //为文件读取成功设置事件  
	    reader.onload=function(e) {  
	        layer.open({
			    content: '图片添加成功!'
			    ,skin: 'msg'
			    ,time: 2 //2秒后自动关闭
			  });
	        imgFile = e.target.result; 
	        if(num == 3){
	        	$('.defaultImg').find('img').hide();
	        	$('.defaultImg').before("<a href='javascript:;'><img src='"+imgFile+"'><img class='delImg' src='images/del.png'></a>");
	        }else{
	        	$('.defaultImg').before("<a href='javascript:;'><img src='"+imgFile+"'><img class='delImg' src='images/del.png'></a>");
	        }
	        _this.value = '';
	        $('.delImg').on('tap',function(){
	        	var _this = this;
	        	setTimeout(function(){
	        		$(_this).parents('a').remove();
	        		var nums = $('.addImg').find('a').length;
		        	if(nums < 4){
		        		$('.defaultImg').find('img').show();
		        	}
	        	},100)
	        })
	    };  
	  	
	    //正式读取文件  
	    reader.readAsDataURL(file);  
	}
	function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }
})

